import os

import pandas as pd

pd.set_option('display.unicode.east_asian_width', True)


def get_filenames(path):
    filenames = []
    for file in os.listdir(path):
        if file.endswith('.docx'):  # 如果文件以'.txt'结尾
            filenames.append(file)
    return filenames


def 检查路径名(filenames):
    l = []
    for filename in filenames:
        if len(filename.split('.')) < 3:
            l.append(filename)

    if len(l) != 0:
        for e in l:
            print(e)
        exit(1)


def 统计时间信息(base_path, dir):
    filenames = get_filenames(base_path + dir)
    检查路径名(filenames)

    l = []
    for filename in filenames:
        date = filename.split('.')[1]
        l.append(date)

    se = pd.Series(l)
    se.drop_duplicates(inplace=True)
    se.sort_values(inplace=True)
    return se


if __name__ == '__main__':
    # BASE_PATH = r"D:\100-Project\2024-2025-1学期安排\武昌首义学院\24101308_《通信数据分析技术（企业）》\作业和报告"
    BASE_PATH = r"D:\100-Project\2024-2025-1学期安排\武昌首义学院\24101309_《通信数据运维技术（企业）》\作业和上机报告"
    se = 统计时间信息(BASE_PATH, r"\作业4")
    print(se.values)
